package gdut.jmxywz.action;

import gdut.jmxywz.been.Teacher;
import gdut.jmxywz.been.Vertical;
import gdut.jmxywz.been.VerticalFile;
import gdut.jmxywz.util.PageModel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

public class VerticalAction extends BaseAction{
	private  static final String  TEACHER_SESSION_KEY = "teacherSessionKey";
	private Teacher  teacher;
		
	private Vertical vertical;
	private PageModel pageModel;
	private int verId;
	/***************分页*****************/
	private int currentPage=1;
	private int pageSize=5;
	
	/***************检索*****************/
	//private String searchSelect="";
	
	private String like="";
	private String where_search="";
	private String where_value="";
	//private String searchValue="";
	
	/**************文件上传****************/
	private List<String> files_content;
	private List<File> upload_file;       
	

	private List<String> upload_fileContentType;
	private List<String> upload_fileFileName;
	private String   savePath;
	private List<VerticalFile> verticalFile ;
	
	/**************excel表导出导入****************/
	private File excelFile;
	private String excelFileContentType;
	private boolean checkbox;
	
	
	
	
	
	
	/***************增加*****************/
	 public String add() throws Exception{
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
		 vertical.setTeacherByEditer(teacher);
boolean bool=this.getCommonService().saveObject(vertical);
    	 
		 if(upload_file!=null)
		
				for(int i=0;i<upload_file.size();i++){//控制上传部分
					String extend_name=getUpload_fileFileName().get(i);
//					System.out.println(extend_name);
					int extend_name_int=extend_name.lastIndexOf(".");//截取扩展名
					extend_name=extend_name.substring(extend_name_int);
								
					java.text.DateFormat df = new java.text.SimpleDateFormat("yyyyMMddHHmmss") ;//生成时间用于重命名文件
				   String datestr = df.format(new java.util.Date()) ;
				   Random rand = new Random();//生成随机数
				   int ram = rand.nextInt(500);
					String ram_str = String.valueOf(ram);
					for(int i_i=0; ram_str.length()<6;i_i++){
						ram_str="0"+ram_str;
					}
					

					
					
					String root = ServletActionContext.getRequest().getRealPath(
							"/accessories/vertical/");//获得文件在服务器的绝对路径
					
					extend_name=datestr+ram_str+extend_name;//合成文件名    时间+随机数+扩展名
//					System.out.println("----文件名-:---"+extend_name+"--------------");
					 savePath=root+"\\"+extend_name;
					
//						System.out.println("----服务器保存路径-:---"+savePath+"--------------");
					 
					String fn=savePath ;
					FileOutputStream fos=new  FileOutputStream(fn);
					
					InputStream fis=new FileInputStream(upload_file.get(i));
					byte[] buffer=new byte[8192];
					int len=0;
					while((len=fis.read(buffer))>0){
					fos.write(buffer,0,len);
					
					}
//					fos.close();
//					fis.close();
					
					VerticalFile afiles=new VerticalFile();
								
					
//					System.out.println();
//					System.out.println("----------第--"+(i+1)+"--文件--------------");
//					System.out.println("----服务器保存路径-:---"+savePath+"--------------");
//					System.out.println("--------文件名:"+upload_fileFileName.get(i)+"--------------");
//					System.out.println("--------文件说明:"+files_content.get(i)+"--------------");
					
					afiles.setVerticalFileUrl("/accessories/vertical/"+extend_name);
					afiles.setVerticalFileName(upload_fileFileName.get(i));
					afiles.setVerticalFileContext(files_content.get(i));
					afiles.setVertical(vertical);	
		
					//在插入附件表
					boolean b2=this.getCommonService().saveObject(afiles);
			
//			文件上传处理结束
			
	     	}

		 if(bool)
		 return SUCCESS;
		 else
			 return "error";
	 }

	public String show() throws Exception{
		String hql="from Vertical where auditing != 0";
		hql = hql +" order by editedTime desc,verId desc,auditing desc";
		pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize, "VerticalShow.action","");
		
			return SUCCESS;
	}

	
	
	
	public String search() throws Exception {
		// TODO Auto-generated method stub
		String hql="from Vertical where auditing != 0";
		
		 String[] parem = null;
   	  
   	  String  search_parameter = "";
   	  String en_where_value="";
   	  
   	 
			HttpServletRequest request = ServletActionContext.getRequest();
			where_value=new String(request.getParameter("where_value").getBytes("ISO-8859-1"),"UTF-8");
			 //
		   	  String searchValue1=where_value;
		   	  //
			//
     if(!"".equals(where_value)&&where_value!=null){
   		  
   		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换
   		  System.out.println("++++-- "+where_value);
   		  
   		  if (like.equals("like")) {
   			hql = hql + " and " + where_search + " like '%"+ searchValue1 + "%' ";
 				//hql = hql + "  and sc." + where_search + " like '%"+ searchValue1 + "%' ";
 			} else {
 				hql = hql + " and " + where_search + " ='"+ searchValue1 + "' ";
 				//hql = hql + "  and sc." + where_search + " ='"+ searchValue1 + "' ";
 			}
   		  
   	  }
   	  
     hql = hql +" order by editedTime desc,verId desc,auditing desc";
   	  
   	  //查询条件
   	  
   	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
   	  
   	  pageModel = new PageModel();
   	  
   	  pageModel=this.getCommonService().findPage(hql, parem, currentPage, pageSize, "VerticalSearch.action",search_parameter);
		
		
		
		return SUCCESS;
		
		
	}

	
	
	/***************详细*****************/
	public String detail() throws Exception {
		// TODO Auto-generated method stub
String hql="from VerticalFile where VerId="+verId;
		
verticalFile=this.getCommonService().findListByHql(hql, null);
		vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
		if(vertical==null)
			return "error";
		else
			return SUCCESS;
	}
	
	
	/***************管理员更新预处理*****************/
	public String preUpdate() throws Exception {
		// TODO Auto-generated method stub
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

		vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
		vertical.setTeacherByAssessor(teacher);
		String hql2="from VerticalFile where verId="+verId;
//		System.out.println(hql2);
		verticalFile=this.getCommonService().findListByHql(hql2, null);
		
//		String hql="from Info as a where a.infoType=3";
//		scientificInfoUpdateList=new ArrayList();
//		scientificInfoUpdateList=this.getCommonService().findListByHql(hql, null);
//		
//		if(scientificInfoUpdate==null||scientificInfoUpdateList==null)
			if(vertical==null)
			return "error";
		else
			return SUCCESS;
	}
	
	/***************非管理员更新预处理*****************/
	public String preUpdateSelf() throws Exception {
		// TODO Auto-generated method stub
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

		vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
if(!vertical.getTeacherByEditer().getTeacherId().equals(teacher.getTeacherId())){
			
			System.out.println("没有修改的权限");
			
			return "error";
		}
		if(!"0".equals(vertical.getAuditing())){
	   		  
	   		System.out.println("已通过审核，不能在修改！");
	   		
	   		return "error";
	   	  }
	 
		String hql2="from VerticalFile where verId="+verId;
//		System.out.println(hql2);
		verticalFile=this.getCommonService().findListByHql(hql2, null);
		
//		String hql="from Info as a where a.infoType=3";
//		scientificInfoUpdateList=new ArrayList();
//		scientificInfoUpdateList=this.getCommonService().findListByHql(hql, null);
//		
//		if(scientificInfoUpdate==null||scientificInfoUpdateList==null)
			if(vertical==null)
			return "error";
		else
			return SUCCESS;
	}
	
	
	/***************更新*****************/
	public String update() throws Exception {
		
		Vertical vertical2=(Vertical)this.getCommonService().findByIntId(vertical.getVerId(), "gdut.jmxywz.been.Vertical");
		vertical2.setVerTitle(vertical.getVerTitle());
		vertical2.setVerNum(vertical.getVerNum());
		vertical2.setVerTime(vertical.getVerTime());
		vertical2.setVerAccount(vertical.getVerAccount());
		vertical2.setVerContext(vertical.getVerContext());
		vertical2.setVerCopartner(vertical.getVerCopartner());
		vertical2.setVerPrincipal(vertical.getVerPrincipal());
		vertical2.setVerRec(vertical.getVerRec());
		vertical2.setVerSort(vertical.getVerSort());
		// TODO Auto-generated method stub
//		System.out.print("==========="+scientificInfoUpdate);
		boolean bl=this.getCommonService().updateObject(vertical2);
//		System.out.print("==========="+scientificInfoUpdate);
//		System.out.print("==========="+bl);
		 if(upload_file!=null)
				
				for(int i=0;i<upload_file.size();i++){//控制上传部分
					String extend_name=getUpload_fileFileName().get(i);
//					System.out.println(extend_name);
					int extend_name_int=extend_name.lastIndexOf(".");//截取扩展名
					extend_name=extend_name.substring(extend_name_int);
								
					java.text.DateFormat df = new java.text.SimpleDateFormat("yyyyMMddHHmmss") ;//生成时间用于重命名文件
				   String datestr = df.format(new java.util.Date()) ;
				   Random rand = new Random();//生成随机数
				   int ram = rand.nextInt(500);
					String ram_str = String.valueOf(ram);
					for(int i_i=0; ram_str.length()<6;i_i++){
						ram_str="0"+ram_str;
					}
					

					
					
					String root = ServletActionContext.getRequest().getRealPath(
							"/accessories/vertical/");//获得文件在服务器的绝对路径
					
					extend_name=datestr+ram_str+extend_name;//合成文件名    时间+随机数+扩展名
//					System.out.println("----文件名-:---"+extend_name+"--------------");
					 savePath=root+"\\"+extend_name;
					
//						System.out.println("----服务器保存路径-:---"+savePath+"--------------");
					 
					String fn=savePath ;
					FileOutputStream fos=new  FileOutputStream(fn);
					
					InputStream fis=new FileInputStream(upload_file.get(i));
					byte[] buffer=new byte[8192];
					int len=0;
					while((len=fis.read(buffer))>0){
					fos.write(buffer,0,len);
					
					}
//					fos.close();
//					fis.close();
					
					VerticalFile afiles=new VerticalFile();
								
					
//					System.out.println();
//					System.out.println("----------第--"+(i+1)+"--文件--------------");
//					System.out.println("----服务器保存路径-:---"+savePath+"--------------");
//					System.out.println("--------文件名:"+upload_fileFileName.get(i)+"--------------");
//					System.out.println("--------文件说明:"+files_content.get(i)+"--------------");
					
					afiles.setVerticalFileUrl("/accessories/vertical/"+extend_name);
					afiles.setVerticalFileName(upload_fileFileName.get(i));
					afiles.setVerticalFileContext(files_content.get(i));
					afiles.setVertical(vertical);	
		
					//在插入附件表
					boolean b2=this.getCommonService().saveObject(afiles);
			
//			文件上传处理结束
			
	     	}
		
		
		if(bl)
			return SUCCESS;
		else
			return "error";
	}
	
	/***************删除*****************/
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		  teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

		vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
		if(vertical!=null){
			
			
			String hql="from VerticalFile where verId="+verId;
	         
			Vertical vertical = new Vertical();
		         
			vertical =(Vertical) this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
		   	  
		         //删除服务器上的附件
		   	  
		   	    List fileList = this.getCommonService().findListByHql(hql, null);
		   	  
		   	    Iterator iter = fileList.iterator();
		   	   
		   	    while(iter.hasNext()){
		   		  
		   	    	VerticalFile verticalFile = (VerticalFile)iter.next();
		   		  
		   		  String path = ServletActionContext.getRequest().getRealPath("/");
		   		  
		   		  path = path + verticalFile.getVerticalFileUrl();
		   		  
		   		  System.out.println("======="+path);
		   		  
		   		  this.getCommonService().deleteObject(verticalFile);
		   		  
		   		  this.deleteFile(path);
		   		  
		   		  System.out.println("===文件删除===");
		   	    }
		   		  
		   		boolean bl=this.getCommonService().deleteObject(vertical);//删除科研著作
		   		
		   		if(bl)
					return SUCCESS;
				else
					return "error";
		   	  }
			
			
			
			else
				return "error";
		
	}
	
	/***************非管理员删除*****************/
	public String deleteSelf() throws Exception {
		// TODO Auto-generated method stub
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

		vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
		

		//判断是否可以删除
  	    if(!vertical.getTeacherByEditer().getTeacherId().equals(teacher.getTeacherId())){
			
			System.out.println("没有删除的权限");
			
			return "error";
		}
		if(!"0".equals(vertical.getAuditing())){
	   		  
	   		System.out.println("已通过审核，不能在修改！");
	   		
	   		return "error";
	   	  }
		
		if(vertical!=null){
			
			
			String hql="from VerticalFile where verId="+verId;
	         
			Vertical vertical = new Vertical();
		         
			vertical =(Vertical) this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
		   	  
		         //删除服务器上的附件
		   	  
		   	    List fileList = this.getCommonService().findListByHql(hql, null);
		   	  
		   	    Iterator iter = fileList.iterator();
		   	   
		   	    while(iter.hasNext()){
		   		  
		   	    	VerticalFile verticalFile = (VerticalFile)iter.next();
		   		  
		   		  String path = ServletActionContext.getRequest().getRealPath("/");
		   		  
		   		  path = path + verticalFile.getVerticalFileUrl();
		   		  
		   		  System.out.println("======="+path);
		   		  
		   		  this.getCommonService().deleteObject(verticalFile);
		   		  
		   		  this.deleteFile(path);
		   		  
		   		  System.out.println("===文件删除===");
		   	    }
		   		  
		   		boolean bl=this.getCommonService().deleteObject(vertical);//删除科研著作
		   		
		   		if(bl)
					return SUCCESS;
				else
					return "error";
		   	  }
			
			
			
			else
				return "error";
		
	}
	
	 /***
	    *  deleteFile  从服务器上删除附件
	    * @param sPath
	    * @return
	    */
		
		public  boolean deleteFile(String sPath) {   
			boolean  flag = false;   
			File   file = new File(sPath);   
		    // 路径为文件且不为空则进行删除   
		    if (file.isFile() && file.exists()) {   
		        file.delete();   
		        System.out.println("---成功从服务器删除文件---");
		        flag = true;   
		    }   
		    return flag;   
		}  
	
	
	/***************show审核信息列表*****************/
	public String audingShow()throws Exception{
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

		String hql=" from Vertical";
		 hql = hql +"  order by auditing asc ,editedTime desc,verId desc";
		pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"VerticalAudingShow.action","");
//		horizontal=(Horizontal)pageModel.getList().get(0);
		
		return SUCCESS;
	}
	/***************show审核信息列表*****************/
	public String selfShow()throws Exception{
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
			String hql=" from Vertical where teacherByEditer.teacherId="+teacher.getTeacherId();
			 hql = hql +"  order by auditing asc ,editedTime desc,verId desc";
		
		pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"VerticalSelfShow.action","");
//		horizontal=(Horizontal)pageModel.getList().get(0);
		
		return SUCCESS;
	}
	
	
	
	
	/***************Search审核列表*****************/		
	public String searchAuding() throws Exception {
		// TODO Auto-generated method stub
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

		String hql="from Vertical";
		
		 String[] parem = null;
   	  
   	  String  search_parameter = "";
   	  String en_where_value="";
   	  
   	 
			HttpServletRequest request = ServletActionContext.getRequest();
			where_value=new String(request.getParameter("where_value").getBytes("ISO-8859-1"),"UTF-8");
			 //
		   	  String searchValue1=where_value;
		   	  //
			//
     if(!"".equals(where_value)&&where_value!=null){
   		  
   		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换
   		  System.out.println("++++-- "+where_value);
   		  
   		  if (like.equals("like")) {
   			hql = hql + "  where " + where_search + " like '%"+ searchValue1 + "%' ";
 				//hql = hql + "  and sc." + where_search + " like '%"+ searchValue1 + "%' ";
 			} else {
 				hql = hql + "  where " + where_search + " ='"+ searchValue1 + "' ";
 				//hql = hql + "  and sc." + where_search + " ='"+ searchValue1 + "' ";
 			}
   		  
   	  }
   	  
     hql = hql +"  order by auditing asc ,editedTime desc,verId desc";
   	  
   	  //查询条件
   	  
   	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
   	  
   	  pageModel = new PageModel();
   	  
   	  pageModel=this.getCommonService().findPage(hql, parem, currentPage, pageSize, "VerticalSearchAuding.action",search_parameter);
		
		
		return SUCCESS;
	}
	
	/***************Search审核列表*****************/		
	public String searchSelf() throws Exception {
		// TODO Auto-generated method stub
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
		 String hql=" from Vertical where teacherByEditer.teacherId="+teacher.getTeacherId();
		 String[] parem = null;
   	  
   	  String  search_parameter = "";
   	  String en_where_value="";
   	  
   	 
			HttpServletRequest request = ServletActionContext.getRequest();
			where_value=new String(request.getParameter("where_value").getBytes("ISO-8859-1"),"UTF-8");
			 //
		   	  String searchValue1=where_value;
		   	  //
			//
     if(!"".equals(where_value)&&where_value!=null){
   		  
   		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换
   		  System.out.println("++++-- "+where_value);
   		  
   		  if (like.equals("like")) {
   			hql = hql + "  and " + where_search + " like '%"+ searchValue1 + "%' ";
 				//hql = hql + "  and sc." + where_search + " like '%"+ searchValue1 + "%' ";
 			} else {
 				hql = hql + "  and " + where_search + " ='"+ searchValue1 + "' ";
 				//hql = hql + "  and sc." + where_search + " ='"+ searchValue1 + "' ";
 			}
   		  
   	  }
   	  
        hql = hql +"  order by auditing asc ,editedTime desc,verId desc";
   	  
   	  //查询条件
   	  
   	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
   	  
   	  pageModel = new PageModel();
   	  
   	  pageModel=this.getCommonService().findPage(hql, parem, currentPage, pageSize, "VerticalSearchSelf.action",search_parameter);
		
		 
		 
		
		return SUCCESS;
	}
	
	
	   /***
     *   inside 对内公布
     */
	  public String inside() throws Exception{
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

    	  
		  vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
    	  //将信息审核为对院内公布 ，即设置auditing为1；
		 if(vertical!=null){
			 vertical.setAuditing("1");
			 vertical.setTeacherByAssessor(teacher);
		  boolean bl=this.getCommonService().updateObject(vertical);
		   if(bl){  
		  return SUCCESS;
		   }
		   return "error";
		 }
		 return "error";
	  }
	  
	
    /***
     *   outside 对外公布
     */
    public String outside() throws Exception{
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

    	vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
    	  //将信息审核为对院内公布 ，即设置auditing为1；
		 if(vertical!=null){
			 vertical.setAuditing("2");
			 vertical.setTeacherByAssessor(teacher);
		  boolean bl=this.getCommonService().updateObject(vertical);
		   if(bl){  
		  return SUCCESS;
		   }
		   return "error";
		 }
		 return "error";
	  }
	
	/***
	 * 
	 *    notAllow 不通过
	 */
    public String notAllow() throws Exception{
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

    	vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
    	  //将信息审核为对院内公布 ，即设置auditing为1；
		 if(vertical!=null){
			 vertical.setAuditing("3");
			 vertical.setTeacherByAssessor(teacher);
		  boolean bl=this.getCommonService().updateObject(vertical);
		   if(bl){  
		  return SUCCESS;
		   }
		   return "error";
		 }
		 return "error";
	  }
	
    
    
	
	/***
	 * 
	 *    rollBack 未审核
	 */
    public String rollBack() throws Exception{
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

    	vertical=(Vertical)this.getCommonService().findByIntId(verId, "gdut.jmxywz.been.Vertical");
    	  //将信息审核为对院内公布 ，即设置auditing为1；
		 if(vertical!=null){
			 vertical.setAuditing("0");
			 vertical.setTeacherByAssessor(teacher);
		  boolean bl=this.getCommonService().updateObject(vertical);
		   if(bl){  
		  return SUCCESS;
		   }
		   return "error";
		 }
		 return "error";
  	  }
    
	
	
    public String importExcel() throws Exception {
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
    	//System.out.print("3333333332222222222222222222222111111111113333333");
    	// TODO Auto-generated method stub
		if(excelFile==null)
		{
			return "error";
			}
				
//System.out.print("3333333333333333333333333333333");
    	int count=0;
		try{
		FileInputStream fis=new FileInputStream(excelFile);
		jxl.Workbook jwb=Workbook.getWorkbook(fis);
		int sheets=jwb.getNumberOfSheets();
		for(int i=0;i<sheets;i++){
			Sheet rs=jwb.getSheet(i);
			int columnNum=rs.getColumns();
			int rowNum=rs.getRows();
			if(rowNum>0&&columnNum!=9){
				System.out.println("--------------------导入格式不对----------------------");
				return "error";
			}
			Cell crl;
			for(int row=1;row<rowNum;row++){
				crl=rs.getCell(0, row);
				String hql="from Vertical stc where stc.verNum='"+crl.getContents()+"'";
				List<Vertical> aa=this.getCommonService().findListByHql(hql, null);
				
			
                 

                 boolean bl;
             
				if(aa.size()==0){//项目未存在
					
					 vertical=new Vertical();
                     vertical.setVerNum(crl.getContents());
                     
                     crl=rs.getCell(1,row);
                     vertical.setVerTitle(crl.getContents());
                     crl=rs.getCell(2,row);
                     vertical.setVerCopartner(crl.getContents());
                     crl=rs.getCell(3,row);
                     vertical.setVerPrincipal(crl.getContents());
                     crl=rs.getCell(4,row);
                     vertical.setVerAccount(Integer.valueOf(crl.getContents()).intValue());
                     crl=rs.getCell(5,row);
                     vertical.setVerRec(Integer.valueOf(crl.getContents()).intValue());
                   crl=rs.getCell(6,row);
                     vertical.setVerTime(new SimpleDateFormat("yyyy-MM-dd").parse(crl.getContents()));
                     crl=rs.getCell(7,row);
                     vertical.setVerSort(crl.getContents());
                     crl=rs.getCell(8,row);
                     vertical.setVerContext(crl.getContents());
                     
                     
                     vertical.setEditedTime(new java.util.Date());
                     vertical.setTeacherByEditer(teacher);
                     vertical.setAuditing("0");
                     
					bl=this.getCommonService().saveObject(vertical);//不存在该项目

					if(!bl){
						System.out.println("------------------存入数据库出错-------------------");
					}
					
					count++;
					
				}
				
				if(aa.size()!=0){//项目已存在
						
					
					
					if(checkbox&&aa.get(0).getAuditing().equals("0")){//判断是否对已存在项目进行更新
						//对已存在项目进行更新	
						
						vertical=aa.get(0);
						 vertical.setVerNum(crl.getContents());
	                     
	                     crl=rs.getCell(1,row);
	                     vertical.setVerTitle(crl.getContents());
	                     crl=rs.getCell(2,row);
	                     vertical.setVerCopartner(crl.getContents());
	                     crl=rs.getCell(3,row);
	                     vertical.setVerPrincipal(crl.getContents());
	                     crl=rs.getCell(4,row);
	                     vertical.setVerAccount(Integer.valueOf(crl.getContents()).intValue());
	                     crl=rs.getCell(5,row);
	                     vertical.setVerRec(Integer.valueOf(crl.getContents()).intValue());
	                     crl=rs.getCell(6,row);
	                     vertical.setVerTime(new SimpleDateFormat("yyyy-MM-dd").parse(crl.getContents()));
	                     crl=rs.getCell(7,row);
	                     vertical.setVerSort(crl.getContents());
	                     crl=rs.getCell(8,row);
	                     vertical.setVerContext(crl.getContents());
	                     
	                     
	                     vertical.setEditedTime(new java.util.Date());
	                     vertical.setTeacherByEditer(teacher);
	                     vertical.setAuditing("0");
						
						bl=this.getCommonService().updateObject(vertical);//对已存在该项目更新
					
						if(!bl){
							System.out.println("------------------存入数据库出错-------------------");
						}
						
						count++;
					}
					
					else{
						System.out.print("项目已存在，但不做更新");//不做任何更新
					}
					
				}
				
				
				
				
			}
		}
		System.out.println("=================一共导入数据数：================="+count);
		jwb.close();
		fis.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
    //管理员导出Excel
    public void exportExcel() throws Exception {
    	
    	
    	// TODO Auto-generated method stub
		try{
			String[] str=new String[]{"项目编号","项目名称","合作单位","负责人","项目资金","来款情况","项目时间","排序等级","备注","发布人","发布时间","审核状态（0==未审核，1==院内公开，2==对外公开,3==审核不通过）","审核信息"};
			List list;
			
				String hql="from Vertical";
				list=this.getCommonService().findListByHql(hql, null);
			
		
			HttpServletResponse response=ServletActionContext.getResponse();
			response.reset();
			response.setContentType("application/vnd.ms-excel");
			response.setContentType("APPLICATION/OCTET-STREAM ");
			response.setHeader("Content-Disposition","attachment; filename="+java.net.URLEncoder.encode("纵向项目.xls","UTF-8"));
			WritableWorkbook wwb=Workbook.createWorkbook(response.getOutputStream());
			WritableSheet sheet=wwb.createSheet("sheet1", 0);
			sheet.setColumnView(0, 20);
			sheet.setColumnView(1, 20);
			sheet.setColumnView(2, 20);
			sheet.setColumnView(3, 20);
			sheet.setColumnView(11, 20);
			Label label=null;
			for(int i=0;i<str.length;i++){
				label=new Label(i,0,str[i]);
				sheet.addCell(label);
			}
			for(int i=0;i<list.size();i++){
				vertical=(Vertical)list.get(i);
				
				label = new Label(0, i+1, vertical.getVerNum());
				sheet.addCell(label);
				label = new Label(1, i+1, vertical.getVerTitle());
				sheet.addCell(label);
				label = new Label(2, i+1, vertical.getVerCopartner());
				sheet.addCell(label);
				label = new Label(3, i+1, vertical.getVerPrincipal());
				sheet.addCell(label);
				label = new Label(4, i+1, String.valueOf(vertical.getVerAccount()));
				sheet.addCell(label);
				label = new Label(5, i+1, String.valueOf(vertical.getVerRec()));
				sheet.addCell(label);
				label = new Label(6, i+1, new SimpleDateFormat("yyyy-MM-dd").format(vertical.getVerTime()));
				sheet.addCell(label);
				label = new Label(7, i+1, vertical.getVerSort());
				sheet.addCell(label);
				label = new Label(8, i+1, vertical.getVerContext());
				sheet.addCell(label);
				label = new Label(9, i+1, vertical.getTeacherByEditer().getTeacherName());
				sheet.addCell(label);
				label = new Label(10, i+1, new SimpleDateFormat("yyyy-MM-dd").format(vertical.getEditedTime()));
				sheet.addCell(label);
				label = new Label(11, i+1, vertical.getAuditing());
				sheet.addCell(label);
//				label = new Label(11, i+1, horizontal.getAssessor().getTeacherName());
//				sheet.addCell(label);
				label = new Label(12, i+1, vertical.getAssessorInfo());
				sheet.addCell(label);
			}
			wwb.write();
			wwb.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
	
	}
    
    //非管理员导出Excel
 public void exportSelfExcel() throws Exception {
	 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);


		String hql=" from Vertical where teacherByEditer.teacherId="+teacher.getTeacherId();
 	// TODO Auto-generated method stub
		try{
			String[] str=new String[]{"项目编号","项目名称","合作单位","负责人","项目资金","来款情况","项目时间","排序等级","备注","发布人","发布时间","审核状态（0==未审核，1==院内公开，2==对外公开,3==审核不通过）","审核信息"};
			List list;
			
				
				list=this.getCommonService().findListByHql(hql, null);
			
			
		
			HttpServletResponse response=ServletActionContext.getResponse();
			response.reset();
			response.setContentType("application/vnd.ms-excel");
			response.setContentType("APPLICATION/OCTET-STREAM ");
			response.setHeader("Content-Disposition","attachment; filename="+java.net.URLEncoder.encode("纵向项目.xls","UTF-8"));
			WritableWorkbook wwb=Workbook.createWorkbook(response.getOutputStream());
			WritableSheet sheet=wwb.createSheet("sheet1", 0);
			sheet.setColumnView(0, 20);
			sheet.setColumnView(1, 20);
			sheet.setColumnView(2, 20);
			sheet.setColumnView(3, 20);
			sheet.setColumnView(11, 20);
			Label label=null;
			for(int i=0;i<str.length;i++){
				label=new Label(i,0,str[i]);
				sheet.addCell(label);
			}
			for(int i=0;i<list.size();i++){
				vertical=(Vertical)list.get(i);
				
				label = new Label(0, i+1, vertical.getVerNum());
				sheet.addCell(label);
				label = new Label(1, i+1, vertical.getVerTitle());
				sheet.addCell(label);
				label = new Label(2, i+1, vertical.getVerCopartner());
				sheet.addCell(label);
				label = new Label(3, i+1, vertical.getVerPrincipal());
				sheet.addCell(label);
				label = new Label(4, i+1, String.valueOf(vertical.getVerAccount()));
				sheet.addCell(label);
				label = new Label(5, i+1, String.valueOf(vertical.getVerRec()));
				sheet.addCell(label);
				label = new Label(6, i+1, new SimpleDateFormat("yyyy-MM-dd").format(vertical.getVerTime()));
				sheet.addCell(label);
				label = new Label(7, i+1, vertical.getVerSort());
				sheet.addCell(label);
				label = new Label(8, i+1, vertical.getVerContext());
				sheet.addCell(label);
				label = new Label(9, i+1, vertical.getTeacherByEditer().getTeacherName());
				sheet.addCell(label);
				label = new Label(10, i+1, new SimpleDateFormat("yyyy-MM-dd").format(vertical.getEditedTime()));
				sheet.addCell(label);
				label = new Label(11, i+1, vertical.getAuditing());
				sheet.addCell(label);
//				label = new Label(11, i+1, horizontal.getAssessor().getTeacherName());
//				sheet.addCell(label);
				label = new Label(12, i+1, vertical.getAssessorInfo());
				sheet.addCell(label);
			}
			wwb.write();
			wwb.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
    
	
	
	
	
	
	
	
	
	
	
	
	
	
	



	

	public Vertical getVertical() {
		return vertical;
	}

	public void setVertical(Vertical vertical) {
		this.vertical = vertical;
	}

	public PageModel getPageModel() {
		return pageModel;
	}
	public void setPageModel(PageModel pageModel) {
		this.pageModel = pageModel;
	}

	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	/*public String getSearchSelect() {
		return searchSelect;
	}
	public void setSearchSelect(String searchSelect) {
		this.searchSelect = searchSelect;
	}*/
	public String getLike() {
		return like;
	}
	public void setLike(String like) {
		this.like = like;
	}
	/*public String getSearchValue() {
		return searchValue;
	}
	public void setSearchValue(String searchValue) {
		this.searchValue = searchValue;
	}*/

	public int getVerId() {
		return verId;
	}

	public void setVerId(int verId) {
		this.verId = verId;
	}

	public List<String> getFiles_content() {
		return files_content;
	}

	public void setFiles_content(List<String> files_content) {
		this.files_content = files_content;
	}

	public List<File> getUpload_file() {
		return upload_file;
	}

	public void setUpload_file(List<File> upload_file) {
		this.upload_file = upload_file;
	}

	public List<String> getUpload_fileContentType() {
		return upload_fileContentType;
	}

	public void setUpload_fileContentType(List<String> upload_fileContentType) {
		this.upload_fileContentType = upload_fileContentType;
	}

	public List<String> getUpload_fileFileName() {
		return upload_fileFileName;
	}

	public void setUpload_fileFileName(List<String> upload_fileFileName) {
		this.upload_fileFileName = upload_fileFileName;
	}

	public String getSavePath() {
		return savePath;
	}

	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}

	public List<VerticalFile> getVerticalFile() {
		return verticalFile;
	}

	public void setVerticalFile(List<VerticalFile> verticalFile) {
		this.verticalFile = verticalFile;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public File getExcelFile() {
		return excelFile;
	}

	public void setExcelFile(File excelFile) {
		this.excelFile = excelFile;
	}

	public String getExcelFileContentType() {
		return excelFileContentType;
	}

	public void setExcelFileContentType(String excelFileContentType) {
		this.excelFileContentType = excelFileContentType;
	}

	public boolean isCheckbox() {
		return checkbox;
	}

	public void setCheckbox(boolean checkbox) {
		this.checkbox = checkbox;
	}

	public String getWhere_search() {
		return where_search;
	}

	public void setWhere_search(String whereSearch) {
		where_search = whereSearch;
	}

	public String getWhere_value() {
		return where_value;
	}

	public void setWhere_value(String whereValue) {
		where_value = whereValue;
	}
	
	
	
	
	
}
